package com.bossien.flink.factory;


import java.lang.reflect.Proxy;
import com.bossien.flink.common.sqlcommand.MapperProxy;
import com.bossien.flink.interfaces.IMapper;
import lombok.Data;

/**
 * @author 胡春林
 */
@Data
public class MapperProxyFactory {

    private static Class<?> iMapper = null;

    public static <T> T newInstance(Class<T> iMapper) {
        MapperProxy mapperProxy = new MapperProxy(iMapper);
        return newInstance(mapperProxy);
    }

    private static <T> T newInstance(MapperProxy mapperProxy) {
        iMapper = mapperProxy.getiMapper();
        return (T)Proxy.newProxyInstance(iMapper.getClassLoader(), new Class[]{iMapper}, mapperProxy);
    }

}

